// ml:run = $bin < input
// ml:opt = 0
// ml:ccf += -g
#include <iostream>
#include <string>

std::string s;
long long n, t, last;

bool judge(long long mid)
{
    long long first = -1, count = 0, now = mid, ti = 0;
    for (long long i = 0; i <= last; i++) {
        ti++;
        if (s[i] == '.') continue;
        if (s[i] == 'S') {
            now++;
            if (first != -1 && now >= count) {
                ti += (i - first) * 2;
                first = -1;
                now -= count;
                count = 0;
            }
            continue;
        }
        if (s[i] == 'H') {
            if (now) now--;
            else {
                count++;
                if (first == -1) first = i;
            }
        }
    }
    int llast = last;
    if (count) {
        for (long long i = last + 1; i < n; i++) {
            ti++;
            if (s[i] == '.') continue;
            if (s[i] == 'S') {
                now++;
                if (first != -1 && now >= count) {
                    llast = i;
                    ti += (i - first);
                    count = 0;
                    break;
                }
                continue;
            }
        }
    }
    if (count) return false;
    /* if (n == 100000) std::cout << llast << " " << last << " " << ti << " " << first << "\n"; */
    if (ti <= t) return true;
    first = -1; count = 0; now = mid; ti = 0;
    for (long long i = 0; i <= last; i++) {
        ti++;
        if (first != -1) if (ti + (llast - first) + (llast - i) <= t) return true;
        if (s[i] == '.') continue;
        if (s[i] == 'S') {
            now++;
            if (first != -1 && now >= count) {
                ti += (i - first) * 2;
                first = -1;
                now -= count;
                count = 0;
            }
            continue;
        }
        if (s[i] == 'H') {
            if (now) now--;
            else {
                count++;
                if (first == -1) first = i;
                if (ti + (llast - first) + (llast - i) <= t) return true;
            }
        }
    }
    /* if (n == 100000) std::cout << llast << " " << " " << last << ti << " " << first << "\n"; */
    if (ti + (llast - first) + (llast - last) <= t) return true;
    return false;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin >> n >> t;
    std::cin >> s;
    last = n - 1;
    for (; last >= 0; last--) if (s[last] == 'H') break;

    long long l = 0, r = n + 1;
    while (l + 1 < r) {
        long long mid = (l + r) / 2;
        if (judge(mid)) r = mid;
        else l = mid;
    }
    if (judge(l)) r = l;
    if (judge(r)) std::cout << r << "\n";
    else {
        std::cout << "-1\n";
    }
}

